﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'proc_cm_GetSiteMapNode')
BEGIN
    PRINT 'Dropping Procedure proc_cm_GetSiteMapNode'
    DROP  Procedure  proc_cm_GetSiteMapNode
END
GO

PRINT 'Creating Procedure proc_cm_GetSiteMapNode'
GO

CREATE PROCEDURE [dbo].[proc_cm_GetSiteMapNode]
	@pNodeId uniqueidentifier = null
	, @pNodeCd nvarchar(20) = null
	, @pGenericPageType varchar(50) = null
AS
BEGIN
	SET NOCOUNT ON

	if @pNodeId is null and @pNodeCd is null
		RAISERROR ('You must provide @pNodeId or @pNodeCd.', 16, 1)

	if @pNodeId is not null
		SELECT 
			[node_id]
			,[node_title]
			,[node_url]
			,[node_cd]
			,[node_description]
			,[parent_node_id]
			,[role]
			,[display_order_num]
			,[use_generic_page_ind]
			,[generic_page_type]
			,[admin_users]
		FROM
			[dbo].[tbl_sitemap] (NOLOCK)
		WHERE
			[node_id] = @pNodeId
	else
		SELECT 
			[node_id]
			,[node_title]
			,[node_url]
			,[node_cd]
			,[node_description]
			,[parent_node_id]
			,[role]
			,[display_order_num]
			,[use_generic_page_ind]
			,[generic_page_type]
			,[admin_users]
		FROM
			[dbo].[tbl_sitemap] (NOLOCK)
		WHERE
			[node_cd] = @pNodeCd
			and [generic_page_type] = @pGenericPageType
END
GO

GRANT EXEC ON dbo.proc_cm_GetSiteMapNode TO PUBLIC
GO

